home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / pxlgt100.zip / LOGTIME.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-05  |  5KB  |  266 lines

  1. {
  2.  
  3. Logs the current time in a file.
  4.  
  5. Version 1.00
  6.  
  7. (c) Copyright 1993, Michael Gallias
  8.  
  9. Target: Real
  10.  
  11. }
  12.  
  13. Program LogTime;
  14.  
  15. Uses CRT, DOS, CmndLine, PasStr;
  16.  
  17. {$M 2048,0,0}
  18.  
  19. Type
  20.   TSetup        = Record
  21.                     Msg1,
  22.                     Msg2        :String;
  23.                     FileName    :String;
  24.                     Store       :Boolean;
  25.                     Display     :Boolean;
  26.                     List        :Boolean;
  27.                   End;
  28.  
  29. Var
  30.   Setup         : TSetup;
  31.  
  32. Procedure FixUnderscore(Var M:String);
  33.  
  34. Var
  35.   x     : Byte;
  36.  
  37. Begin
  38.   For x:=1 to Length(M) do
  39.     If M[x]='_' Then M[x]:=' ';
  40. End;
  41.  
  42. Procedure SetOpts;
  43.  
  44. Var
  45.   X     : Byte;
  46.   Item  : CommandItem;
  47.  
  48. Begin
  49.   Setup.FileName:='C:\TEMP\BOOTLOG';
  50.   Setup.Msg1:='Last bootup: ';
  51.   Setup.Msg2:='.';
  52.   Setup.Store:=True;
  53.   Setup.Display:=True;
  54.   Setup.List:=False;
  55.  
  56.   For X:=1 to ParamCount do
  57.   Begin
  58.     CommandOption(case_Leave, X, Item);
  59.     With Item do
  60.     If Tag = cmnd_DString Then
  61.     Begin
  62.       If (SName1 = 'f') Or (SName1 = 'F') Then Setup.FileName:=SName2;
  63.       If (SName1 = '1') Then Setup.Msg1:=SName2;
  64.       If (SName1 = '2') Then Setup.Msg2:=SName2;
  65.     End
  66.     Else
  67.     If Tag = cmnd_Switch Then
  68.     Begin
  69.       If Switch[1] in ['d','D'] Then
  70.       Begin
  71.         If Switch[Length(Switch)]='-' Then
  72.           Setup.Display:=False
  73.         Else
  74.           Setup.Display:=True;
  75.       End
  76.       Else
  77.       If Switch[1] in ['s','S'] Then
  78.       Begin
  79.         If Switch[Length(Switch)]='-' Then
  80.           Setup.Store:=False
  81.         Else
  82.           Setup.Store:=True;
  83.       End
  84.       Else
  85.       If Switch[1] in ['l','L'] Then
  86.       Begin
  87.         Setup.List:=True;
  88.         Setup.Display:=False;
  89.         Setup.Store:=False;
  90.       End;
  91.     End;
  92.   End;
  93.   FixUnderscore(Setup.Msg1);
  94.   FixUnderscore(Setup.Msg2);
  95. End;
  96.  
  97. Const
  98.   MaxTimes      = 170;
  99.  
  100. Type
  101.   TTime         = Array [1..MaxTimes] Of DateTime;
  102.                   {1 is the oldest time, MaxTimes is the newest}
  103.   FTime         = File Of TTime;
  104.  
  105. Var
  106.   Time          : TTime;
  107.  
  108.  
  109. Procedure LoadFile;
  110.  
  111. Var
  112.   C     : Char;
  113.   F     : FTime;
  114.  
  115. Begin
  116.   Assign(F,Setup.FileName);
  117.   Reset(F);
  118.   If IOResult>0 Then
  119.   Begin
  120.     WriteLn('Warning, Can''t open ',Setup.FileName,'.');
  121.     WriteLn;
  122.     WriteLn('Select:');
  123.     WriteLn('          1.  Create Blank File');
  124.     WriteLn('          2.  Exit');
  125.     WriteLn;
  126.     Repeat
  127.       C:=ReadKey;
  128.     Until C in ['1','2',#27];
  129.     If C='1' Then
  130.     Begin
  131.       FillChar(Time,SizeOf(Time),0);
  132.       Write('Creating New File ... ');
  133.       Assign(F,Setup.FileName);
  134.       Rewrite(F);
  135.       If IOResult>0 Then
  136.       Begin
  137.         WriteLn('Error creating file.');
  138.         Halt;
  139.       End;
  140.       Write(F,Time);
  141.       Close(F);
  142.       WriteLn('Done.');
  143.     End
  144.     Else
  145.     Begin
  146.       WriteLn('Exit.');
  147.       Halt;
  148.     End;
  149.   End
  150.   Else
  151.   Begin
  152.     Read(F,Time);
  153.     Close(F);
  154.   End;
  155. End;
  156.  
  157. Function TimeString(TheTime:DateTime):String;
  158.  
  159. Var
  160.   S, T  :String[20];
  161.   TS    :String;
  162.  
  163. Begin
  164.   With TheTime do
  165.   Begin
  166.     Str(Day:2,S);
  167.     Str(Month:2,T);
  168.     Str(Year,TS);
  169.     SpacesToZeros(S,S);
  170.     SpacesToZeros(T,T);
  171.     TS:=S+'/'+T+'/'+TS+'  ';
  172.  
  173.     Str(Hour:2,S);
  174.     Str(Min:2,T);
  175.     SpacesToZeros(S,S);
  176.     SpacesToZeros(T,T);
  177.     TS:=TS+S+':'+T;
  178.     Str(Sec:2,T);
  179.     SpacesToZeros(T,T);
  180.     TS:=TS+':'+T;
  181.   End;
  182.  
  183.   TimeString:=TS;
  184. End;
  185.  
  186. Procedure DisplayLastTime;
  187. Begin
  188.   If Time[MaxTimes].Day=0 Then Exit;
  189.  
  190.   Write(Setup.Msg1);
  191.   Write(TimeString(Time[MaxTimes]));
  192.   WriteLn(Setup.Msg2);
  193. End;
  194.  
  195. Procedure UpdateTime;
  196.  
  197. Var
  198.   X     : Word;
  199.  
  200. Begin
  201.   For X:=1 to MaxTimes-1 do
  202.     Time[X]:=Time[X+1];
  203.  
  204.   With Time[MaxTimes] do
  205.   Begin
  206.     GetDate(Year, Month, Day, X);
  207.     GetTime(Hour, Min, Sec, X);
  208.   End;
  209. End;
  210.  
  211. Procedure UpdateFile;
  212.  
  213. Var
  214.   C     : Char;
  215.   F     : FTime;
  216.  
  217. Begin
  218.   C:='0';
  219.   Assign(F,Setup.FileName);
  220.   Reset(F);
  221.   If IOResult>0 Then C:='1';
  222.   Write(F,Time);
  223.   If IOResult>0 Then C:='1';
  224.   Close(F);
  225.   If IOResult>0 Then C:='1';
  226.   If C='1' Then
  227.   Begin
  228.     WriteLn('Error Saving File ',Setup.FileName,'.');
  229.     WriteLn('Press any key ...');
  230.     C:=ReadKey;
  231.   End;
  232. End;
  233.  
  234. Procedure DisplayList;
  235.  
  236. Var
  237.   X     : Word;
  238.  
  239. Begin
  240.   WriteLn;
  241.   WriteLn('Recorded Times (LOGTIME Version 1.00)');
  242.   WriteLn;
  243.   For X:=1 to MaxTimes do
  244.     If Time[X].Day<>0 Then WriteLn(TimeString(Time[X]));
  245.   WriteLn;
  246. End;
  247.  
  248. Begin
  249.   DirectVideo:=False;
  250.  
  251.   SetOpts;
  252.   LoadFile;
  253.  
  254.   If Setup.Display Then
  255.     DisplayLastTime;
  256.  
  257.   If Setup.Store Then
  258.   Begin
  259.     UpdateTime;
  260.     UpdateFile;
  261.   End;
  262.  
  263.   If Setup.List Then
  264.     DisplayList;
  265. End.
  266.